package com.itheima.controller;

import com.itheima.entity.Emp;
import com.itheima.entity.Fenlei;
import com.itheima.entity.PageBean;
import com.itheima.entity.Result;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/admin/category")
public class FenleiControllerr {
    @Autowired
    EmpService empService;
    /*
    * 修改
    * */
    @PutMapping()
    public Result update(@RequestBody Fenlei fenlei) {
        empService.xiugai(fenlei);

        return Result.success();
    }
    /*
    * 分页查询
    * */
    @GetMapping("page")
    public Result page(Integer page, Integer PageSize) {
        PageBean pageBean = empService.page(page, PageSize);
        //3.封装并返回查询结果
        return Result.success(pageBean);
    }
    /*
     *禁用/启用分类
     * */
    @PostMapping("/status/{status}")
    public Result st(@PathVariable Integer id){
        Emp empResult = empService.std(id);

        return Result.success(empResult);

    }

    /*
     * 新增分类
     *
     * */
    @PostMapping("")
    public Result add(@RequestBody Fenlei Fenlei) {
        // 1.接受请求参数
        log.info("添加员工：{}", Fenlei);
        //2.调用业务层
        empService.addE(Fenlei);
        //3.封装
        return Result.success();
    }
    /*
     * 根据id删除分类
     * */
    @DeleteMapping("")
    public Result remove(@PathVariable Integer id) {
        //1. 接受请求参数: 请求路径,@PathVariable  + 变量

        //2. 调用业务层，实现删除指定部门的功能
        empService.removeById(id);
        //3. 封装处理结果数据

        return Result.success();//code=1,msg=success,data=null
    }
    //根据类型查询
    @GetMapping("list")
    public Result fen(Map map) {

        empService.fen(map);
        return Result.success(map);
    }
}
